$(document).ready(function(){
	$("#pageFormContent2").hide();
	$("#pageFormContent3").hide();
	$("#priceTab1").hide();
	$("#priceTab2").hide();
	var tdRow = $("#tdFenquses");	//横向- tr
	var priceSty;	//风格
	$("#theNextBtn").click(function(){
		priceSty = $("input[name='priceSty']:radio:checked").val();
		var returnNum = checkContext();
		if(returnNum == 0){
			//文本域扩大基数：*16
			$.post("../partitionJson!findEPartitions.action",{"channelNumber":$("#channelNum_import").val()},function(data){
				if(priceSty == 0){
					//横向
					tdRow.append("<td height='20' class='pricetdClass'><div style='width:130px;height:20px;line-height:20px;text-align:center;'>重量阶段</div></td>");
					$(data.epartitions).each(function(){
						tdRow.append("<td width='200' height='20' class='pricetdClass'>"+this.partition_name+"</td>");
					});
					$("#priceContext1").attr("cols",(tdRow.children('td').size()) * 16);
//					document.getElementById("priceContext1td").rowspan = 45;
					$("#priceTab1").show("slow");
				}else{
					//纵向
//					document.getElementById("priceContext1td").rowspan = 0;
					$("#priceTab2").append("<tr>" +
					"<td height='20' class='pricetdClass'><div style='width:130px;height:20px;line-height:20px;text-align:center;'>重量阶段</div></td>" +
					"<td height='20' id='tdwidthaa' width='100' rowspan='15'><textarea name='xxxx' rows='8' id='priceContext2' cols='200'></textarea></td>"+
					"</tr>");
					var ii = 0;	//文本域行数 *2
					$(data.epartitions).each(function(){
						$("#priceTab2").append("<tr>" +
						"<td height='20' width='100' class='pricetdClass'>" +
						this.partition_name +"</td>"+"</tr>");
						ii++;
					});
					$("#tdwidthaa").attr("rowspan",ii+1);
					$("#priceContext2").attr("rows", (ii)*1.4);
					$("#priceTab2").show("slow");
				}
			});
			$("#sfenquName").attr("value",sfenqu.innerText);
			$("#clientClassName").attr("value",kehulei.innerText);
			$("#pageFormContent1").fadeOut("normal");
			$("#pageFormContent2").show("slow");
		}else{
			switch(returnNum){
				case 1:
					alertMsg.error("请选择起始分区");
					break;
				case 2:
					alertMsg.error("请选择报价类别(客户类别)");
					break;
//				case 3:
//					alertMsg.error("请选择报价类型");
//					break;
				case 4:
					alertMsg.error("请选择生效日期");
					break;
				case 5:
					alertMsg.error("请选择结束日期");
					break;
				case 6:
					alertMsg.error("请正确选择结束日期");
					break;
			}
		}
	});
	$("#theBackBtn").click(function(){
		$("#pageFormContent2").fadeOut("normal");
		$("#priceTab1").hide();
		tdRow.children('td').remove();
		$("#priceContext1").attr("value","");
		$("#priceTab2").children('tr').remove();
		$("#priceTab2").hide();
		$("#pageFormContent1").show("slow");
	});
	$("#theSecondNextBtn").click(function(){
		var priceContext ;
		if(priceSty == 0){
			priceContext = $("#priceContext1").val();
		}else{
			priceContext = $("#priceContext2").val();
		}
		$.post("../price_engenderPriceTable.action",{"priceSty":priceSty,"priceContext":priceContext},function(priceses){
			if(priceSty==0){
				$("#priceTable").attr("width","1230");
			}else{
				$("#priceTable").attr("width","1230");
			}
			$("#priceTableBody").html(priceses);
		});
		
		$("#pageFormContent2").fadeOut("normal");
		$("#pageFormContent3").show("slow");
	});
	$("#theSecondBackBtn").click(function(){
		
		$("#pageFormContent3").fadeOut("normal");
		$("#pageFormContent2").show("slow");
		$("#priceTableBody").html("");
	});
	
	$("#handleFareIn").hide();
	$("#handleFare").click(function(){
		if($("#handleFare").attr("checked")){
			$("#handleFareIn").show("slow");
			$("#handleFareIn").attr("value",$("#handleFare_im").val());
		}else{
			$("#handleFareIn").fadeOut("normal");
			$("#handleFareIn").attr("value","0");
		}
	});
	$("#registerFareIn").hide();
	$("#registerFare").click(function(){
		if($("#registerFare").attr("checked")){
			$("#registerFareIn").show("slow");
			$("#registerFareIn").attr("value",$("#registerFare_im").val());
		}else{
			$("#registerFareIn").fadeOut("normal");
			$("#registerFareIn").attr("value","0");
		}
	});
	$("#otherFareIn").hide();
	$("#otherFare").click(function(){
		if($("#otherFare").attr("checked")){
			$("#otherFareIn").show("slow");
			$("#otherFareIn").attr("value",$("#otherFare_im").val());
		}else{
			$("#otherFareIn").fadeOut("normal");
			$("#otherFareIn").attr("value","0");
		}
	});
});

var sfenqu ;
var kehulei	;
//var baojialei ;
function checkContext() {
		sfenqu = $("#sfenqu option:selected").get(0);
		kehulei = $("#clientClasses option:selected").get(0);
	//	baojialei = $("#baojiaTypes option:selected").get(0);
		if(sfenqu.value == ""){
			return 1;
		}else if(kehulei.value == -1){
			return 2;	
		}
//		else if(baojialei.value == -1){
//			return 3;
//		}
		else if($("#priceStartDate").val() == ""){
			return 4;
		}else if($("#priceEndDate").val() == ""){
			return 5;
		}else if($("#priceEndDate").val() <= $("#priceStartDate").val()){
			return 6;
		}else{
			return 0;
		}
		
	}
function zhuanhuan(str){
	while(!(parseFloat(str) > 0)){
		str = str.substring(1,str.length);
	}
	return parseFloat(str);
}